<include file='Index/header' />
<div class="row">
	<br>
	<div class="col-sm-12">
		<div class="col-sm-1" style="padding-top:5px;width:120px">
			<label class="control-label">操作日期：</label>
		</div>
		<div class="col-sm-2">
			<input id="start_date" class="form-control"></input>
		</div>
		<div class="col-sm-1" style="padding-top:5px;width:10px">至</div>
		<div class="col-sm-2">
			<input id="end_date" class="form-control"></input>
		</div>
		<div class="col-sm-2" style="padding-left:100px;padding-top:5px">
			<label for="type_search" class="control-label">类型：</label>
		</div>
		<div class="col-sm-3">
      <select class="form-control" id="type_search" name="type_search">
	      <option value="" selected="selected">全部</option>
				<option value="增加积分">增加积分</option>
				<option value="减少积分">减少积分</option>
			</select>
    </div>
	</div>
	<div class="col-sm-12">
		<br>
	<table id="admin_list_table" class="table table-hover table-bordered table-striped table-striped">
		<thead>
			<tr>
				<td>编号</td>
				<td>操作类型</td>
				<td>操作数值</td>
				<td>操作原因</td>
				<td>操作日期</td>
				<td>操作人</td>
			</tr>
		</thead>
		<tbody>

		</tbody>
	</table>
</div>
</div>

<include file='Index/footer' />

<script>
$(document).ready(function() {
	loadDatetimepicker('start_date');
	loadDatetimepicker('end_date');
	loadTable();
});


var table;
function loadTable(){
	table = $('#admin_list_table').DataTable({
		"bProcessing": true,
		"bDestroy": true,
		"sPaginationType" : "input",
		"oLanguage" : {
              "sLengthMenu": "每页显示 _MENU_ 条记录",
              "sZeroRecords": "抱歉， 没有找到",
              "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
              "sInfoEmpty": "没有数据",
              "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
              "sZeroRecords": "没有检索到数据",
               "sSearch": "搜索: &nbsp",
              "oPaginate": {
                "sFirst": "首页",
                "sPrevious": "前一页",
                "sNext": "后一页",
                "sLast": "尾页"
              }
          }, 
		"ajax":'{:U("Admin/admin/getAdminCredit/")}',
		"columns": [
					{ "data": 'id' },
					{ "data": 'type' },
	        { "data": 'change_credit' },
	        { "data": 'reason' },
	        { "data": 'createtime' },
	        { "data": 'admin' }
    ],
    "columnDefs": [
    {
			"targets": 0,
			"render": function (data, type, row, table) {
        return table.row + 1;
      }
    },
    {
			"targets": 1,
			"render": function (data, type, row, table) {
				switch(data){
					case '0':
					 data = '减少积分';
					 break;
					case '1':
						data = '增加积分';
						break;
				}
        return data;
      }
    },
    {
			"targets": 5,
			"render": function (data, type, row, table) {
        return data==null?'':transNull(data.name);
      }
    }
   ]
	});

	$.fn.dataTable.ext.search.push(
	    function( settings, data, dataIndex ) {
	        var min = new Date($('#start_date').val());
	        var max = new Date($('#end_date').val());
	        var now = new Date( data[4] ); 

	        if ( ( isNaN( min ) && isNaN( max ) ) ||
	             ( isNaN( min ) && now <= max ) ||
	             ( min <= now   && isNaN( max ) ) ||
	             ( min <= now   && now <= max ) )
	        {
	            return true;
	        }
	        return false;
	    }
	);	

	$('#start_date, #end_date').datetimepicker().on('changeDate', function(e){
      table.draw();
  });

	$("#type_search").on( 'change', function () {
 		table.column(1).search(this.value).draw();
  });
}

function view(user_id){
	$.ajax({
			url: '{:U("Admin/User/getUser/")}',
			type: 'post',
			dataType: 'json',
			data:{
				"user_id":user_id
			}
		})
		.success(function(data){
			$('#phone').html(data.phone);
			$('#createtime').html(data.createtime);
			$('#credit').html(data.credit);
			$('#name').html(data.name);
			
			switch(data.status){
				case '0':
					$('#status').html("正常");
					break;
				case '1':
					$('#status').html("已禁用");
					break;
			}

			$('#user_detail_modal').modal({
				backdrop : "static"
			});
	});
}

function forbid(user_id, status){
	$.ajax({
		url: '{:U("Admin/User/updateUser/")}',
		type: 'post',
		dataType: 'json',
		data:{
			"user_id":user_id,
			"status":status
		}
	})
	.success(function(data){
		location.reload();
	});
}

function del(user_id){
	if(!confirm("是否删除该用户？（状态不可逆）")){
		return;
	}
	$.ajax({
		url: '{:U("Admin/User/deleteUser/")}',
		type: 'post',
		dataType: 'json',
		data:{
			"user_id":user_id
		}
	})
	.success(function(data){
		location.reload();
	});
}
var user_id = '';
function modCredit(user_id){
	window.user_id = user_id;
	$('#user_credit_modal').modal({
		backdrop : "static"
	});
}
</script>
